<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="list.push('马超')">添加元素</button>
        <button @click="list.pop()">删除元素</button>
        <button @click="list.splice(1, 0, '孙尚香')">添加到指定位置元素</button>
        <!-- <button @click="list[0] = '曹操' ">修改下标</button> -->
        <button @click=" $set(list, 0, '曹操') ">修改下标</button>
        <ul>
            <li v-for="item in list">{{ item }}</li>
        </ul>
    </div>

    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    list: ['刘备','关羽','张飞','赵云']
                }
            },
            watch: {
                // 侦听list数组的变化
                // 怎么侦听数组就能侦听到了？还不用开深度侦听？
                // vue对数组的一些方法进行了重新包裹，所以我们能侦听到
                list () {
                    console.log('list有变化了')
                }
            }
        })
    </script>
</body>
</html>